<?php
namespace app\api\job;

use app\api\controller\GameNotify;
use think\facade\Log;
use think\queue\Job;

class SendSmsJob {
    public function fire(Job $job, $data)
    {
        $c = new GameNotify();
        $result = $c->game_notify($data['order_no']);
        if($result['status'] == true) {
            $job->delete();
        } else {
        // 通知失败
            if ($job->attempts() > 3) {
                // 超过重试次数
                $this->failed($data);
                $job->delete();
            } else {
                // 1秒后重试
                $job->release(1);
            }
        }
    }

    public function failed($data){
        Log::error("订单：{$data['order_no']} 发货失败");
    }
}
